// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   AddressAction.java

package com.iphaeton.lms.action.address;

import com.iphaeton.common.helper.UserSession;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.business.address.IAddressService;
import com.iphaeton.lms.pojo.address.Address;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;

// Referenced classes of package com.iphaeton.lms.action.address:
//            AddressBizSupportAction

public class AddressAction extends AddressBizSupportAction
{

    public AddressAction()
    {
    }

    public ActionForward addAddressForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        java.util.List list;
        try
        {
            list = address.findSort();
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("sort", list);
        return mapping.findForward("add_address");
    }

    public ActionForward addAddress(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        daf = (DynaActionForm)form;
        String name = (String)daf.get("name");
        String sort_id = (String)daf.get("sort_id");
        String add = (String)daf.get("address");
        String mail = (String)daf.get("mail");
        String tel = (String)daf.get("tel");
        String mobil = (String)daf.get("mobil");
        String msn = (String)daf.get("msn");
        String qq = (String)daf.get("qq");
        String chuanzhen = (String)daf.get("chuanzhen");
        Address addr = new Address();
        addr.setName(name);
        addr.setSortId(sort_id);
        if(!address.equals("") && address != null)
            addr.setAddress(add);
        if(!mail.equals("") && mail != null)
            addr.setMail(mail);
        if(!tel.equals("") && tel != null)
            addr.setTel(tel);
        if(!mobil.equals("") && mobil != null)
            addr.setMobil(mobil);
        if(!msn.equals("") && msn != null)
            addr.setMsn(msn);
        if(!qq.equals("") && qq != null)
            addr.setQq(qq);
        if(!chuanzhen.equals("") && chuanzhen != null)
            addr.setChuanzhen(chuanzhen);
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            addr.setUserId(user_id);
            addr = address.save(addr);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        return mapping.findForward("addressList");
    }

    public ActionForward addressList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        java.util.List list;
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            list = address.findAddress(user_id, "");
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("address_list");
    }

    public ActionForward removeAddress(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        try
        {
            address.remove(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        return mapping.findForward("addressList");
    }

    public ActionForward addressDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        Address a;
        try
        {
            a = address.findAddressById(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("address", a);
        return mapping.findForward("address_detail");
    }

    private static Logger logger;
    private DynaActionForm daf;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.address.AddressAction.class.getName());
    }
}
